#include "stdafx.h"
#include "runtime_exceptions.h"
#include "runtime_types.h"
#include "runtime_typecasts.h"

void Variant::setEmpty()
{
	type=0;value.clear();
}

bool Variant::isEmpty()
{
	return type==0;
}

Variant::operator String()
{
	switch (type)
	{
	case 1:
		return std::to_wstring((long double)boost::any_cast<int>(value));
	case 2:
		return std::to_wstring((long double)boost::any_cast<short>(value));
	case 3:
		return std::to_wstring((long double)boost::any_cast<double>(value));
	case 4:
		return std::to_wstring((long double)boost::any_cast<unsigned char>(value));
	case 5:
		return boost::any_cast<String>(value);
	default:
		return L"";
	}
}

Variant::operator double()
{
	switch (type)
	{
	case 1:
		return boost::any_cast<int>(value);
	case 2:
		return boost::any_cast<short>(value);
	case 3:
		return boost::any_cast<double>(value);
	case 4:
		return boost::any_cast<unsigned char>(value);
	case 5:
		return CDbl(boost::any_cast<String>(value));
	default:
		return 0;
	}
}

Variant::Variant(String v):type(5),value(v)
{

}

Variant::Variant(const wchar_t* v):type(5),value(v){

}

Variant::Variant(unsigned char v) :type(4),value(v)
{

}

Variant::Variant(double v) :type(3),value(v)
{

}

Variant::Variant(short v) :type(2),value(v)
{

}

Variant::Variant(int v) :type(1),value(v)
{

}

Variant::Variant() :type(0)
{

}

namespace boost
{
	void throw_invalid_array_index_error(){
		throw runtimeException(runtimeException::fbSubscriptOutOfRange);
	}
}